<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>
ServiceLocator class
</TITLE>

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../resources/stylesheet.css" TITLE="Style">
</HEAD>

<BODY BGCOLOR="white">


<!-- ========= START OF TOP NAVBAR ======= -->

<table border="0" width="100%">
<tr>
<td width="50%">
<p align="left">
<a href="http://mvvmbasics.mobilemotion.eu/" target="_blank" title="MVVMbasics Homepage"><img src="../../resources/logo_mvvmbasics.png" alt="MVVMbasics Logo" border="0"></a>
</p>
</td>
<td width="50%">
<p align="right">
<a href="http://www.mobilemotion.eu/" target="_blank" title="mobilemotion.eu Homepage"><img src="../../resources/logo_mobilemotion.png" alt="mobilemotion.eu Logo" border="0"></a>
</p>
</td>
</tr>
</table>

<HR>

<p><a href="../../index.htm" title="MVVMbasics Class Reference Homepage">Back to Class Reference home page</a></p>

<!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">MVVMbasics.Helpers</FONT>
<BR>
Class ServiceLocator
</H2>

<CODE>
<B>MVVMbasics.Helpers.ServiceLocator</B>
<br>&nbsp;
</CODE>
<HR>
<CODE>
&nbsp;<br>
public class <B>ServiceLocator</B>
</CODE>

<P>
Service locator that allows services to be registered and retrieved. All services must implement the <a href="../Services/IService.htm" title="IService">IService</a> interface in order to be detected by <code>ServiceLocator</code>.
</P>

<hr>

<!-- ======== METHOD SUMMARY ======== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#Register(IService)">Register</a></B>(<a href="../Services/IService.htm" title="IService">IService</a> service)</CODE>
<BR>
<span class="Indented">Registers an instance of a certain service.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#Register(T)">Register&lt;T&gt;</a></B>() where T : <a href="../Services/IService.htm" title="IService">IService</a></CODE>
<BR>
<span class="Indented">Registers a reference to a certain service type, without instantly instantiating it.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#RegisterAll(Assembly)">RegisterAll</a></B>(<a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx" target="_blank" title="System.Reflection.Assembly">Assembly</a> assembly = null)</CODE>
<BR>
<span class="Indented">Traverses all services that are located in a given assembly and registers their types, without instantly instantiating them.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#RegisterAll(string,Assembly)">RegisterAll</a></B>(string ns, <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx" target="_blank" title="System.Reflection.Assembly">Assembly</a> assembly = null)</CODE>
<BR>
<span class="Indented">Traverses all services that are located in a given namespace inside a given assembly and registers their types, without instantly instantiating them.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>bool&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#Contains(T)">Contains&lt;T&gt;</a></B>()</CODE>
<BR>
<span class="Indented">Returns TRUE if a certain kind of service has been registered, FALSE otherwise.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>T&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#Retrieve(T)">Retrieve&lt;T&gt;</a></B>()</CODE>
<BR>
<span class="Indented">Creates a service instance, stores and returns it, or throws an exception if no matching service has been registered.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>T&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#RetrieveOnce(T)">RetrieveOnce&lt;T&gt;</a></B>()</CODE>
<BR>
<span class="Indented">Creates and returns a service instance without storing it, or throws an exception if no matching service has been registered.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>bool&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#TryRetrieve(T)">TryRetrieve&lt;T&gt;</a></B>(out T serviceInstance)</CODE>
<BR>
<span class="Indented">Creates a service instance, stores it, and returns TRUE, if a matching service has been registered. If no matching service is found, returns FALSE.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>bool&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#TryRetrieveOnce(T)">TryRetrieveOnce&lt;T&gt;</a></B>(out T serviceInstance)</CODE>
<BR>
<span class="Indented">Creates a service instance and returns TRUE, if a matching service has been registered. If no matching service is found, returns FALSE.</span>
</TD>
</TR>
</TABLE>
&nbsp;

<!-- ========= METHOD DETAIL ======== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>

<A NAME="Register(IService)"><!-- --></A><H3>
Register</H3>
<CODE>public void <B>Register</B>(<a href="../Services/IService.htm" title="IService">IService</a> service)</CODE>
<p class="Indented">Registers an instance of a certain service.</p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>service</CODE> - Service to be registered.<br>
</p>
</div>

<HR>

<A NAME="Register(T)"><!-- --></A><H3>
Register&lt;T&gt;</H3>
<CODE>public void <B>Register&lt;T&gt;</B>() where T : <a href="../Services/IService.htm" title="IService">IService</a></CODE>
<p class="Indented">Registers a reference to a certain service type, without instantly instantiating it.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be registered (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<HR>

<A NAME="RegisterAll(Assembly)"><!-- --></A><H3>
RegisterAll</H3>
<CODE>public void <B>RegisterAll</B>(<a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx" target="_blank" title="System.Reflection.Assembly">Assembly</a> assembly = null)</CODE>
<p class="Indented">Traverses all services that are located in a given assembly and registers their types, without instantly instantiating them.</p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>assembly</CODE> - The assembly to be scanned. If NULL or not specified, the calling  assembly will be scanned.<br>
</p>
</div>

<HR>

<A NAME="RegisterAll(string,Assembly)"><!-- --></A><H3>
RegisterAll</H3>
<CODE>public void <B>RegisterAll</B>(string ns, <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx" target="_blank" title="System.Reflection.Assembly">Assembly</a> assembly = null)</CODE>
<p class="Indented">Traverses all services that are located in a given namespace inside a given assembly and registers their types, without instantly instantiating them.</p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>ns</CODE> - Namespace to be scanned. If ends with '.*', also sub-directories will be scanned. If NULL, the whole assembly will be scanned.<br>
<CODE>assembly</CODE> - The assembly to be scanned. If NULL, the calling assembly will be scanned.<br>
</p>
</div>

<HR>

<A NAME="Contains(T)"><!-- --></A><H3>
Contains&lt;T&gt;</H3>
<CODE>public bool <B>Contains&lt;T&gt;</B>()</CODE>
<p class="Indented">Returns TRUE if a certain kind of service has been registered, FALSE otherwise.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be retrieved (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<div class="Indented">
<B>Returns:</B>
<p class="Indented">
TRUE if a certain kind of service has been registered, FALSE otherwise.
</p>
</div>

<HR>

<A NAME="Retrieve(T)"><!-- --></A><H3>
Retrieve&lt;T&gt;</H3>
<CODE>public T <B>Retrieve&lt;T&gt;</B>()</CODE>
<p class="Indented">Creates a service instance, stores and returns it, or throws an exception if no matching service has been registered.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be retrieved (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<div class="Indented">
<B>Returns:</B>
<p class="Indented">
Instance of the requested service.
</p>
</div>

<HR>

<A NAME="RetrieveOnce(T)"><!-- --></A><H3>
RetrieveOnce&lt;T&gt;</H3>
<CODE>public T <B>RetrieveOnce&lt;T&gt;</B>()</CODE>
<p class="Indented">Creates and returns a service instance without storing it, or throws an exception if no matching service has been registered.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be retrieved (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<div class="Indented">
<B>Returns:</B>
<p class="Indented">
Instance of the requested service.
</p>
</div>

<HR>

<A NAME="TryRetrieve(T)"><!-- --></A><H3>
TryRetrieve&lt;T&gt;</H3>
<CODE>public bool <B>TryRetrieve&lt;T&gt;</B>(out T serviceInstance)</CODE>
<p class="Indented">Creates a service instance, stores it, and returns TRUE, if a matching service has been registered. If no matching service is found, returns FALSE.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be retrieved (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<div class="Indented">
<B>Out Parameters:</B>
<p class="Indented">
<CODE>serviceInstance</CODE> - Instance of the requested service.<br>
</p>
</div>

<div class="Indented">
<B>Returns:</B>
<p class="Indented">
TRUE if the requested service was found, FALSE otherwise.
</p>
</div>

<HR>

<A NAME="TryRetrieveOnce(T)"><!-- --></A><H3>
TryRetrieveOnce&lt;T&gt;</H3>
<CODE>public bool <B>TryRetrieveOnce&lt;T&gt;</B>(out T serviceInstance)</CODE>
<p class="Indented">Creates a service instance and returns TRUE, if a matching service has been registered. If no matching service is found, returns FALSE.</p>

<div class="Indented">
<B>Type Parameters:</B>
<p class="Indented">
<CODE>T</CODE> - Type of service to be retrieved (must be a subclass of <a href="../Services/IService.htm" title="IService">IService</a>).<br>
</p>
</div>

<div class="Indented">
<B>Out Parameters:</B>
<p class="Indented">
<CODE>serviceInstance</CODE> - Instance of the requested service.<br>
</p>
</div>

<div class="Indented">
<B>Returns:</B>
<p class="Indented">
TRUE if the requested service was found, FALSE otherwise.
</p>
</div>

<!-- ========= END OF CLASS DATA ========= -->
<HR>

</body>
</HTML>